#ifndef VIMAGEVIEWER_H
#define VIMAGEVIEWER_H

#include "MainFrm.h"
#include "explorer/addFilmDialog.h"
#include "explorer/dicomDirItem.h"
#include <tprintwindow.h>
#include "movieviewer.h"
using namespace std;
//void setValue(int, int);



	

typedef std::vector<TToolBarInfo> TToolBarList;

class VImageViewerWidget : public QWidget
{
	Q_OBJECT
	
public:	
	QMainWindow * mainWindowParent;
	VImageViewerWidget(QWidget* Parent = NULL);
	~VImageViewerWidget();

public:
	void mouseReleaseEvent(QMouseEvent * event);
	VDialogWait waitDialog;
	bool connected;
	//QDialog waitDialog;	
	
	const TToolBarList &getToolBarList(){ return toolbarList; }
	QMenu *getMenu(){return menu2; }
	//void addFile(char *);
public slots:
	void onDICOMDIRECTORY();
	void onCREATETREE(QString);
	void onADDFILES(QStringList);
	void onDOWNLOADFILES(QStringList);
	//void onTRYADDFILESFAST(QStringList);
	void onTRYDOWNLOADFILESFAST(QStringList);
	void onTRYDOWNLOADFILESFASTFromFileVREF(QString);
	void ONTBCHANGED(){
		int f = 4;
	}
	void onCHANGEPOSITIONMAIN1(){ mainFrame->onCHANGEPOSITIONMAIN1();	repaint();	  
								  actViewOneStudy->setDisabled(true);
	}
	void onCHANGEPOSITIONMAIN2(){ mainFrame->onCHANGEPOSITIONMAIN2();	repaint();	
								  actViewOneStudy->setDisabled(false);
	}
	void onCHANGEPOSITIONMAIN3(){ mainFrame->onCHANGEPOSITIONMAIN3();	repaint();	
								  actViewOneStudy->setDisabled(false);
	}
	void onCHANGEPOSITIONMAIN4(){ mainFrame->onCHANGEPOSITIONMAIN4();   repaint();									
								  actViewOneStudy->setDisabled(false);
								}
	void onVIEWONESTUDY()		{ mainFrame->onVIEWONESTUDY();	
								  repaint();	
								  ContainerPanel::repaintImageAll();																		  
	}
	void onMOVEMPR()		{ mainFrame->onMOVEMPR();																  
	}
	

	void onAUTOFILLSTUDIESFORFOUR()	{ mainFrame->onCHANGEPOSITIONMAIN4();   repaint(); 
								  mainFrame->onAUTOFILLSTUDIES(); 
								  actOneMainFrame->setChecked(true);
								  actViewOneStudy->setDisabled(false);
	}
	void onAUTOFILLSTUDIES()	{
								  mainFrame->onAUTOFILLSTUDIES(); 								  
	}
	void onGONEXTIMAGE(){
		ContainerPanel::setQuickly(1000);
		ContainerPanel::goNextImage();
		 repaint();
	}
	void onGOPREVIMAGE(){
		ContainerPanel::setQuickly(1000);
		ContainerPanel::goPrevImage();
		repaint(); 
	}

	void onGONEXTIMAGE10(){
		ContainerPanel::setQuickly(1000);
		ContainerPanel::goNextImage10();
		repaint();
	}
	void onGOPREVIMAGE10(){
		ContainerPanel::setQuickly(1000);
		ContainerPanel::goPrevImage10();
		repaint(); 
	}

	void onGONEXTIMAGEMOVIE(){		
		ContainerPanel::goNextImage();
		repaint();
	}
	void onGOPREVIMAGEMOVIE(){	
		ContainerPanel::goPrevImage();
		repaint(); 
	}
	void onGOFIRSTIMAGEMOVIE(){		
		ContainerPanel::goFirstImage();
		repaint();
	}
	void onGOLASTIMAGEMOVIE(){		
		ContainerPanel::goLastImage();
		repaint();
	}
	void onGOPREVSERIES(){		
		connect(&waitDialog, SIGNAL(showEventSignal()), SLOT(goPrevSeries()));		
		waitDialog.openWaitDialog();		
	}
	void onGONEXTSERIES(){	
		connect(&waitDialog, SIGNAL(showEventSignal()), SLOT(goNextSeries()));		
		waitDialog.openWaitDialog();	
	}
	void onGOPREVSTUDY(){	
		connect(&waitDialog, SIGNAL(showEventSignal()), SLOT(goPrevStudy()));		
		waitDialog.openWaitDialog();		
	}
	void onGONEXTSTUDY(){			
		connect(&waitDialog, SIGNAL(showEventSignal()), SLOT(goNextStudy()));		
		waitDialog.openWaitDialog();		
	}
	void goNextStudy(){	
			waitDialog.repaint();
			disconnect(&waitDialog, SIGNAL(showEventSignal()), this, SLOT(goNextStudy()));
			ContainerPanel::flushOneAllActiveTopPanels();
			ContainerPanel::goNextStudy();
			repaint(); 			
			waitDialog.closeWaitDialog();	
	}
	void goPrevStudy(){	
		waitDialog.repaint();
		disconnect(&waitDialog, SIGNAL(showEventSignal()), this, SLOT(goPrevStudy()));
		ContainerPanel::flushOneAllActiveTopPanels();
		ContainerPanel::goPrevStudy();
		repaint(); 			
		waitDialog.closeWaitDialog();	
	}

	void goNextSeries(){	
		waitDialog.repaint();
		disconnect(&waitDialog, SIGNAL(showEventSignal()), this, SLOT(goNextSeries()));
		ContainerPanel::flushOneAllActiveTopPanels();
		ContainerPanel::goNextSeries();
		repaint(); 			
		waitDialog.closeWaitDialog();	
	}
	void goPrevSeries(){	
		waitDialog.repaint();
		disconnect(&waitDialog, SIGNAL(showEventSignal()), this, SLOT(goPrevSeries()));
		ContainerPanel::flushOneAllActiveTopPanels();
		ContainerPanel::goPrevSeries();
		repaint(); 			
		waitDialog.closeWaitDialog();	
	}

	void onCHANGEPOSITIONFRAME1(){			mainFrame->onCHANGEPOSITIONFRAME1(); }
	void onCHANGEPOSITIONFRAME2(){			mainFrame->onCHANGEPOSITIONFRAME2(); }
	void onCHANGEPOSITIONFRAME3(){			mainFrame->onCHANGEPOSITIONFRAME3(); }
	void onCHANGEPOSITIONFRAME4(){			mainFrame->onCHANGEPOSITIONFRAME4(); }
	void onCHANGEPOSITIONFRAMECUSTOM(){		mainFrame->onCHANGEPOSITIONFRAMECUSTOM(); }
	
	void onCHANGEPOSITIONSTUDY1(){			mainFrame->onCHANGEPOSITIONSTUDY1(); }
	void onCHANGEPOSITIONSTUDY2(){			mainFrame->onCHANGEPOSITIONSTUDY2(); }
	void onCHANGEPOSITIONSTUDY3(){			mainFrame->onCHANGEPOSITIONSTUDY3(); }
	void onCHANGEPOSITIONSTUDY4(){			mainFrame->onCHANGEPOSITIONSTUDY4(); }
	void onCHANGEPOSITIONSTUDYCUSTOM(){		mainFrame->onCHANGEPOSITIONSTUDYCUSTOM(); };
	
	void onCHOSEPANEL(){					mainFrame->onCHOSEPANEL();}
	void onSetWL(){							mainFrame->onSETWL();}
	void onMOVEIMAGE(){						mainFrame->onMOVEIMAGE();		}
	void onCONTRASTIMAGE(){					mainFrame->onCONTRASTIMAGE();	}
	void onHIDEOVERLAY(){					mainFrame->onHIDEOVERLAY();		}
	void onHIDEOVERLAYMPR(){				mainFrame->onHIDEOVERLAYMPR();	}

	void onSHOWREFLINE(){					mainFrame->onSHOWREFLINE();		
											if(!refLine->isChecked() && refLineAll->isChecked()){
												refLineAll->setChecked(false);
												onSHOWREFLINEALL();
											}
	}
	void onSHOWREFLINEALL(){				mainFrame->onSHOWREFLINEALL();	
										if(refLineAll->isChecked() && !refLine->isChecked()){
												refLine->setChecked(true);
												onSHOWREFLINE();
										}
	}

	void onTURNVERT(){						mainFrame->onTURNVERT();		}
	void onTURNHOR(){						mainFrame->onTURNHOR();			}
	void onREFLECT(){						mainFrame->onREFLECT();			}
	void onROTATERIGHT(){					mainFrame->onROTATERIGHT();		}
	void onROTATELEFT(){					mainFrame->onROTATELEFT();		}
	void onMPRPLANE(){						mainFrame->onMPRPLANE();			repaint();	}
	void onDO2MPRPLAINES(){					mainFrame->onDO2MPRPLAINES();	repaint();	}
	void onSIZEDIST(){						mainFrame->onSIZEDIST();		repaint();	}
	void onSETSCALE(){						mainFrame->onSETSCALE();		repaint();	}

	void onTEXT(){							mainFrame->onTEXT();			repaint();	}
	void onANGLE(){							mainFrame->onANGLE();			repaint();	}
	void onCURVE(){							mainFrame->onCURVE();			repaint();	}
	void onSPOT(){							mainFrame->onSPOT();			repaint();	}
	void onDELETEMARKS(){					mainFrame->onDELETEMARKS();		repaint();	}
	void onHIDEMARKS(){						mainFrame->onHIDEMARKS();		repaint();	}

	void onFILEADD();
	void onSETVIEWCHOSEN(){					mainFrame->onSETVIEWCHOSEN();	repaint();}
	void onSETVIEWUNCHOSEN(){				mainFrame->onSETVIEWUNCHOSEN();	repaint();}
	void onSETVIEWALL(){					mainFrame->onSETVIEWALL();		repaint();}

	void onCHECKEVEN(){						mainFrame->onCHECKEVEN();		repaint();}
	void onCHECKODD(){						mainFrame->onCHECKODD();		repaint();}
	void onUNCHECKALL(){					mainFrame->onUNCHECKALL();		repaint();}
	

	void onNOFILTER(){						mainFrame->onNOFILTER();		repaint();}
	void onBLURFILTER(){					mainFrame->onBLURFILTER();		repaint();}
	void onSHARPFILTER(){					mainFrame->onSHARPFILTER();		repaint();}
	
	
		
public slots:
	/*)void onCONNECT(){				
		mainFrame->onCONNECT();
		setFocus();
	}
	*/
	void onVIEWMOVIE(){
		mainFrame->setMOVIE(true);
		TMovieViewer movie(1, ContainerPanel::getMaxNumberImgInSeries()); 
		connect(&movie, SIGNAL(signalNextImage()), SLOT(onGONEXTIMAGEMOVIE()));
		connect(&movie, SIGNAL(signalPrevImage()), SLOT(onGOPREVIMAGEMOVIE()));
		connect(&movie, SIGNAL(signalFirstImage()), SLOT(onGOFIRSTIMAGEMOVIE()));
		connect(&movie, SIGNAL(signalLastImage()), SLOT(onGOLASTIMAGEMOVIE()));
		//movie.setModal(true);
		//movie.show();
		movie.setWindowModality(Qt::WindowModal);	
		movie.setWindowFlags(movie.windowFlags() | Qt::WindowStaysOnTopHint);
		movie.setMinimumSize(250, 100);
		movie.setMaximumSize(250, 100);
		QPoint pos(mainWindowParent->pos().x(), mainWindowParent->pos().y() + mainWindowParent->height() - 100 - 5);
		movie.move(pos);
		movie.exec();	
		mainFrame->setMOVIE(false);
		return;
		movie.setGeometry(mainWindowParent->x() + 100, mainWindowParent->y() + 100, 512, 512); 
		QList <QImage> * listImages = new QList <QImage>;
		QList <DICOMStruct *> listDicomStructs;
		DICOMStruct * dicomStructClicked;
		if(Panel::clickedImagePanel != NULL)
			dicomStructClicked = ((ImagePanel *)Panel::clickedImagePanel)->dicomStruct;
		if(Panel::clickedImagePanel != NULL && dicomStructClicked != NULL){
			Panel::setFirst(Panel::firstDicomFile->first);
			ContainerPanel panel;
			DICOMStruct * dicomStruct = Panel::currentDicomFile->current;
			while(dicomStruct != NULL){
				if(Panel::clickedImagePanel->verifyDicomStruct(dicomStruct)){					
					listDicomStructs << dicomStruct;
				}
				dicomStruct = Panel::getNext();
			}				
		}
		movie.setListDicomStructs(listDicomStructs);
		if(((ImagePanel *)Panel::clickedImagePanel)->representationParameters.windowValue == -999999 || ((ImagePanel *)Panel::clickedImagePanel)->representationParameters.levelValue == -999999)
			movie.setListImages(dicomStructClicked->representationParameters.windowValue, dicomStructClicked->representationParameters.levelValue);
		else
			movie.setListImages(((ImagePanel *)Panel::clickedImagePanel)->representationParameters.windowValue, ((ImagePanel *)Panel::clickedImagePanel)->representationParameters.levelValue);
		movie.exec();			
		mainFrame->setMOVIE(false);
	}
	

public slots:
/*	void onOVERLAYSETUP(){		
		//mainFrame->onFileAdd();	
		mainFrame->onOVERLAYSETUP();
		setFocus();
	}
*/
private slots:	
	void paintEvent     (QPaintEvent *event);
	void keyPressEvent  (QKeyEvent   *event);
	void wheelEvent		(QWheelEvent *event);
	void closeEvent		(QCloseEvent *event);
	void mouseMoveEvent	(QMouseEvent *event);
	void leaveEvent		(QEvent		 *event);  
	void keyReleaseEvent(QKeyEvent   *event);
	void focusOutEvent  (QFocusEvent *event);
	void focusInEvent   (QFocusEvent *event);
	void onHELP();
	void onABOUT();
protected:
	bool winEvent		( MSG * message, long * result );
	void showEvent		( QShowEvent *event );	
	
public:
	TAddFilmDialog * aa;
	TPrintWindow * printWindow;
	//void setValue(int, int);
private:	
	TToolBarList toolbarList;
	QString filePath;	
	QActionGroup *actGroup1;
	QActionGroup *actGroup4;
	QActionGroup *actGroup6;
	QActionGroup *actGroup7;
	QActionGroup *actGroup8;
	QActionGroup *actGroup9;
	QAction		 *prevAct;
	QAction		 *onHideMarkAct;
	QAction		 *actMoveImage;
	QAction		 *actOneMainFrame;
	QAction		 *actViewOneStudy;
	QAction		 *mprPlaneMove;
	QAction		 *refLine;	
	QAction		 *refLineAll;
	QToolBar *tb1;
	QToolBar *tb2;
	QToolBar *tb3;
	QToolBar *tb4;
	QToolBar *tb5;
	QToolBar *tb6;
	QToolBar *tb7;
	QToolBar *tb8;
	QToolBar *tb9;
	QToolBar *tb10;
	void makeToolbars();	//
	
	void makeMenu();
	//
	CMainFrame *mainFrame;
	//
public:
	void hide();
	QMenu		 *menu1;
	QMenu		 *menu2;
	QMenu		 *menu3;
	QMenu		 *menu4;
	QMenu		 *menu5;
	QMenu		 *menu6;	
private slots:
	void checkTB1Group();
	void checkTB4Group( QAction *act );
	void checkTB6Group( QAction *act );
	void checkTB9Group( QAction *act);
	void checkTB6HideMark();
	void onPRINT();
	void clearDicomDirStructs();	
	void onExpressionEditor();
	void onOverlayEditor();
	void onDicomTagDialog();
	void addRoman();
	void addVlad();	
	//static void loadFromURL(QUrl url, QString curFilter = "", BOOLEAN noMessage = true);
	//void triggeredTB1( QAction *act ){ actGroup4->actions().first()->trigger(); }
};


class AboutDialog : public QDialog{
	Q_OBJECT	
public:
	AboutDialog();
protected:		
	void paintEvent(		QPaintEvent * event);
	void mousePressEvent(	QMouseEvent * event);
};
void getFromRomanManager(QString fileRef, QString fileName, int numberThreads, QString filter = "");




#endif